#include <stdio.h>
#include <string.h>

#include "device.h"

void at24c02_test(void)
{
    char str[20] = "1234567890abcde";
    char buffer[20];
    device_t *at24cxx;
    
    printf("%s\r\n", __FUNCTION__);
    
    at24cxx = device_open("at24c02", DEVICE_RDWR);
    if(!at24cxx) {
        printf("open at24c02 faied\r\n");
        return;
    }
    
    if(device_pwrite(at24cxx, str, sizeof(buffer), 7) != sizeof(buffer)) {
        printf("write at24cxx faied\r\n");
    }
    memset(buffer, 0, sizeof(buffer));
    if(device_pread(at24cxx, buffer, sizeof(buffer), 7) != sizeof(buffer)) {
        printf("read at24cxx faied\r\n");
    }
    printf("read:\r\n%s\r\n", buffer);
    
    if(device_pwrite(at24cxx, str, sizeof(buffer), 17) != sizeof(buffer)) {
        printf("write at24cxx faied\r\n");
    }
    memset(buffer, 0, sizeof(buffer));
    if(device_pread(at24cxx, buffer, sizeof(buffer), 17) != sizeof(buffer)) {
        printf("read at24cxx faied\r\n");
    }
    printf("read:\r\n%s\r\n", buffer);
    
    device_close(at24cxx);
}
